/*
 *  连号区间数 2013 省赛
 * */

#include <iostream>
#include <algorithm>
using namespace std;
const int N = 500010;

int f[N];
int n;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  cin >> n;

  for (int i = 1; i <= n; ++i) {
    cin >> f[i];
  }

  int res = 0;

  for (int i = 1; i <= n; ++i) {
      int maxValue = -N, minValue = N;
      for (int j = i; j <= n; ++j) {
          maxValue = max(maxValue, f[j]);
          minValue = min(minValue, f[j]);

          if (maxValue - minValue == n - 1) {
              res ++;
          }
      }
  }

  return 0;
}